package module.building.view.Recruit
{
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.TextInput;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	
	import main.App;
	
	import module.building.event.BuildEvent;
	import module.building.model.dataObj.OrderObj;
	import module.main.view.ResourceConst;

	public class RecruitArmsItem extends UIComponent
	{
		/**
		 *招募士兵/生产Item面板 
		 */		
		private var _recruitArmsItemBg:UIComponent;
		private var _outputBg:UIComponent;
		private var _outputLabel:Label;
		private var _armsFraem:UIComponent;
		private var _recruitTimeBg:UIComponent;
		private var _recruitTimeTxt:Label;
		private var _needGoldSp:UIComponent;
		private var _needGoldLabel:Label;
		private var _getExperienceSp:UIComponent;
		private var _getExperienceLabel:Label;
		public function RecruitArmsItem()
		{
			initView();
		}
		private function initView():void
		{
			this.width = 135.9;
			this.height = 175.8;
			_recruitArmsItemBg = new UIComponent();
			_recruitArmsItemBg.backgroundSkin = ResourceConst.RECRUIT_ARMS_BG;
			_recruitArmsItemBg.width = 129.9;
			_recruitArmsItemBg.height = 174.9;
			
			_outputBg = new UIComponent();
			_outputBg.backgroundSkin = ResourceConst.IMG_OUT_PUT_RE;
			_outputBg.height = 27.9;
			_outputBg.width = 51.0;
			
			_recruitTimeBg = new UIComponent();
			_recruitTimeBg.backgroundSkin = ResourceConst.RECRUIT_ARMS_TIME_BG;
			_recruitTimeBg.height = 37.0;
			_recruitTimeBg.width = 135.9;
			
			_needGoldSp = new UIComponent();
			_needGoldSp.backgroundSkin = ResourceConst.BUILD_ICON_GOLD;
			
			_getExperienceSp = new UIComponent();
			_getExperienceSp.backgroundSkin = ResourceConst.GRADE_ICON;
			_outputLabel = new Label();
			_recruitTimeTxt = TextFieldFactory.getInstance().getLabel("equipmentInterface_order_time_min",[1,0]);
			_needGoldLabel = new Label();
			_getExperienceLabel = new Label();
			setPosition();
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT,outHandler);
		}
		private function mouseOverHandler(e:MouseEvent):void
		{
			var $col:uint = 0x00ff33;
			_recruitArmsItemBg.filters = [new GlowFilter($col,0.8, 16, 16, 4, BitmapFilterQuality.MEDIUM, false, false)];
		}
		private function outHandler(e:MouseEvent):void
		{
			_recruitArmsItemBg.filters = [];
		}
		private function clickHandler(e:MouseEvent):void
		{
			var produceEvent:BuildEvent = new BuildEvent(BuildEvent.PRODUCE);
			produceEvent.data = _produceObj;
			this.dispatchEvent(produceEvent);
		}
		private function setPosition():void
		{
			setRecruitArmsItemBg();
			setRecruitTimeBg();
			setNeedGoldSp();
			setGetExperienceSp();
		}
		private function setRecruitArmsItemBg():void
		{
			_recruitArmsItemBg.x = (this.width - _recruitArmsItemBg.width) / 2;
			_recruitArmsItemBg.y = (this.height - _recruitArmsItemBg.height) / 2;
			addChild(_recruitArmsItemBg);
		}
		private function setOutputBg():void
		{
			_outputBg.x = 0;
			_outputBg.y = 0;
			_outputLabel.x = (_outputBg.width - _outputLabel.width) / 2;
			_outputLabel.y = (_outputBg.height - _outputLabel.height) / 2 + 3;
			this.addChild(_outputBg);
			_outputBg.addChild(_outputLabel);
		}
		private function setRecruitTimeBg():void
		{
			_recruitTimeBg.x = 0;
			_recruitTimeBg.y = 91;
			_recruitTimeTxt.x = (_recruitTimeBg.width - _recruitTimeTxt.width) / 2;
			_recruitTimeTxt.y = (_recruitTimeBg.height - _recruitTimeTxt.height) / 2;
			this.addChild(_recruitTimeBg);
			_recruitTimeBg.addChild(_recruitTimeTxt);
		}
		private function setNeedGoldSp():void
		{
			_needGoldSp.width = 15.3;
			_needGoldSp.height = 15.3;
			_needGoldSp.backgroundAuto = false;
			_needGoldSp.x = 40;
			_needGoldSp.y = 132;
			_needGoldLabel.x = _needGoldSp.x + 6 + _needGoldSp.width;
			_needGoldLabel.y = _needGoldSp.y;
			addChild(_needGoldSp);
			addChild(_needGoldLabel);
		}
		private function setGetExperienceSp():void
		{
			_getExperienceSp.height = 15.3;
			_getExperienceSp.width = 15.9;
			_getExperienceSp.backgroundAuto = false;
			_getExperienceSp.x = _needGoldSp.x;
			_getExperienceSp.y = _needGoldSp.y + 3 + _needGoldSp.height;
			_getExperienceLabel.x = _needGoldLabel.x;
			_getExperienceLabel.y = _getExperienceSp.y;
			addChild(_getExperienceSp);
			addChild(_getExperienceLabel);
		}
		/**
		 *提供一个修改数据的接口 
		 * @param data
		 * 
		 */		
		private var _produceObj:OrderObj;
		public function changeData(data:Object):void
		{
			_produceObj = data as OrderObj;	
			_outputLabel.text = _produceObj.output.toString();
			_recruitTimeTxt.text = _produceObj.time.toString() + "分钟";
			_needGoldLabel.text = "-" + _produceObj.gold.toString();
			setOutputBg();
		}
	}
}